﻿using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XW.Utils;
using static System.Net.Mime.MediaTypeNames;

namespace XW.Core;

public static class DifyHelper
{
    private const string token = "app-fcGNne01EhSD5PkVxEm0tzIi";
    public static async Task<string> ChatAsync(string message)
    {
       var result = EasyHttp.With("http://122.226.108.134:2580/v1/chat-messages").HeaderCustome("Authorization", "Bearer " + token).PostForJson(new
        {
            inputs = new {
                lan = "zh"
            },
            query = message,
            response_mode = "streaming",
            conversation_id = "018c7f3d-a672-4de6-bd07-6147e150cff3",
            user = "abc-123", 
        });

        //var httpClient = new HttpClient();
        //httpClient.BaseAddress = new Uri("http://122.226.108.134:2580/v1");
        //httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);
        ////httpClient.DefaultRequestHeaders.Add("Content-Type", "application/json");
        //var mssage = new HttpRequestMessage(HttpMethod.Post, "chat-messages");

        //var todoItemJson = new StringContent(
        //    JsonConvert.SerializeObject(),
        //    Encoding.UTF8,
        //    Application.Json);
        //var resultmsg = await httpClient.PostAsync("chat-messages", todoItemJson);

        return result; 
    }
}